package fr.poc.rest.resources;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.stereotype.Component;

import fr.poc.domain.Couple;

@Path("/")
@Component
public class SimpleResource {

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Path("/hello")
	public String hello() {
		return "Hello World";
	}

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Path("/split")
	public String[] split(@QueryParam("chaine") String chaine) {
		if (chaine == null)
			return new String[] {};

		return chaine.split(";");
		// return new String[]{"toto","titi"};
	}

	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	@Path("/add")
	public int add(Couple couple) {
		if (couple != null)
			return couple.getA() + couple.getB();
		else
			return 0;

	}

}
